package com.mandao.concurrency.example.atomic;

import com.mandao.concurrency.annotations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAdder;

/**
 * 线程安全性:
 *  *   原子性:提供了互斥访问,同一时刻只能有一个线程来对它进行操作
 *  *   atomicReference
 * @author 蜗牛
 */
@Slf4j
@ThreadSafe
public class AtomicExample4 {

    public static AtomicReference<Integer> count = new AtomicReference(0);

    public static void main (String[] args){
        count.compareAndSet(0,1);
        count.compareAndSet(0,3);
        count.compareAndSet(1,5);
        count.compareAndSet(3,2);
        log.info("count:{}",count.get());

    }
}
